package com.hfkh.keyun.controller.frontend;

import com.hfkh.keyun.common.ApiResult;
import com.hfkh.keyun.entity.VisitHistory;
import com.hfkh.keyun.service.VisitHistoryService;
import com.hfkh.keyun.util.PageResult;
import com.hfkh.keyun.vo.VisitHistoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/app/visitHistory")
@Api(tags = "历史记录管理")
public class VisitHistoryControllerApp {

    @Resource
    private VisitHistoryService visitHistoryService;

    @ApiOperation("按条件查询观看历史列表")
    @GetMapping("/selVisitHistory")
    public ApiResult selVisitHistory(Integer userId){
       List<VisitHistory>  visitHistoryList=visitHistoryService.selVisitHistory(userId);
        return  ApiResult.success(visitHistoryList);
    }

    @ApiOperation("按条件查询观看历史列表并分页")
    @GetMapping("/selVisitHistoryPage")
    public ApiResult selVisitHistoryPage(@RequestParam(required = true)Integer userId, @RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10") Integer size){
        PageResult<List<VisitHistory>> listPageResult = visitHistoryService.selVisitHistoryPage(userId, page,
                size);
        return  ApiResult.success(listPageResult);
    }

    @ApiOperation("按id查询观看视频列表")
    @GetMapping("/selVisitHistoryById")
    public ApiResult selVisitHistoryById(Integer id){
        VisitHistory visitHistoryList=visitHistoryService.selVisitHistoryById(id);
        return  ApiResult.success(visitHistoryList);
    }

    @ApiOperation("按id删除观看历史")
    @GetMapping("/delVisitHistoryById")
    public ApiResult delVisitHistoryById(Integer id){
        visitHistoryService.removeById(id);
        return  ApiResult.ok("删除成功", "头像上传成功！");
    }


    @ApiOperation("新增历史列表")
    @PostMapping("/addVisitHistory")
    public ApiResult addVisitHistory(VisitHistoryVo visitHistoryVo){
        VisitHistory visitHistory=new VisitHistory();
        BeanUtils.copyProperties(visitHistoryVo,visitHistory);
         visitHistoryService.save(visitHistory);
        return  ApiResult.success("新增历史记录");
    }

}
